// 运动障碍物类
#pragma once
#include "GameObject.h"
#include <vector>

enum MovementType
{
    MOVEMENT_RANDOM,      // 随机移动
    MOVEMENT_OSCILLATE    // 往复平移
};

class MovingObstacle : public GameObject
{
public:
    MovingObstacle();
    ~MovingObstacle();

    bool Initialize(LPDIRECT3DDEVICE9 device, MovementType moveType, const D3DXVECTOR3& size);
    void Update(float deltaTime) override;
    void Render(LPDIRECT3DDEVICE9 device) override;
    void Cleanup() override;

    void SetMovementBounds(float minX, float maxX, float minZ, float maxZ);
    void SetStaticObjects(const std::vector<GameObject*>* staticObjects);
    void SetTerrain(class Terrain* terrain) { m_pTerrain = terrain; }
    void InitializeOscillateMovement();  // 在SetPosition后调用，初始化往复运动

private:
    void UpdateRandomMovement(float deltaTime);
    void UpdateOscillateMovement(float deltaTime);
    void ChangeRandomDirection();
    bool CheckCollisionWithStaticObjects();

    LPD3DXMESH m_pMesh;
    LPDIRECT3DTEXTURE9 m_pTexture;
    MovementType m_movementType;
    D3DXVECTOR3 m_size;
    D3DCOLOR m_color;

    // 运动参数
    D3DXVECTOR3 m_velocity;
    float m_speed;
    float m_changeDirectionTimer;
    float m_changeDirectionInterval;

    // 往复运动参数
    D3DXVECTOR3 m_oscillateStart;
    D3DXVECTOR3 m_oscillateEnd;
    bool m_oscillateForward;

    // 碰撞检测
    const std::vector<GameObject*>* m_pStaticObjects;
    class Terrain* m_pTerrain;

    // 地图边界
    float m_minX, m_maxX, m_minZ, m_maxZ;
};
